package exception.demo2;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class PWDemo {
    public static void main(String[] args) throws FileNotFoundException {
        //定义一个文件流
        FileOutputStream fos=new FileOutputStream("fox.txt");
        //定义一个转换流
        OutputStreamWriter osw=new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        //定义一个缓存字符流
        BufferedWriter bw=new BufferedWriter(osw);
        //定义换行写方法,同时设置自动换行刷新
        PrintWriter pw=new PrintWriter(bw,true);
        //定义扫描仪
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入内容：");
        while (true){
            String line=sc.nextLine();
            if ("exit".equals(line)){
                break;
            }
            pw.println(line);
        }
        pw.close();
    }
}
